package org.lee.validate.controller;

import org.lee.validate.vo.request.HelloRequest;
import org.lee.validate.vo.resp.Result;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * UserController
 *
 * @author dralee
 * @date 2021-12-24 16:05:27
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping
    public Result getUser(@Validated @NotNull(message = "用户name不能为空") @RequestParam("name") String name) {
        return Result.success("get用户name为" + name + "的信息如下...");
    }

    @GetMapping("{id}")
    public Result user(@PathVariable("id") @NotNull(message = "用户id不能为空") Integer id) {
        return Result.success("用户id为" + id + "的信息如下...");
    }

    @PostMapping
    public Result update(@Validated @RequestBody HelloRequest request) {
        return Result.success("更新用户成功: " + request);
    }

    @PutMapping
    public Result put(@Validated @RequestBody HelloRequest request) {
        return Result.success("保存用户成功: " + request);
    }

    @DeleteMapping("/{id}")
    public Result del(@Validated @PathVariable("id") @NotNull(message = "用户id不能为空") Integer id) {
        return Result.success("删除用户成功: " + id);
    }

}
